/*
 * Helstius--Basic chemistry application
 * This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 * Copyright 2012 Jaked122
 */
package org.helstius.Gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import org.helstius.Gui.*;

public class ChemApp extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ChemApp frame = new ChemApp();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	Bartest qas;
	PercentCompositionForm percentcomposition;
	MolarityGui mo;
	EquationBalancingGui adddd;
	TitrationGui tit;

	/**
	 * Create the frame.
	 */
	public ChemApp() {
		setTitle("Chemistry Application");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		percentcomposition = new PercentCompositionForm();
		qas = new Bartest();
		JPanel panel = new JPanel();
		mo = new MolarityGui();
		JLabel lblStoichiometry = new JLabel("Stoichiometry");

		JButton btnPercentComposition = new JButton("Percent Composition");
		btnPercentComposition.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				percentcomposition.setVisible(true);
			}
		});
		adddd = new EquationBalancingGui();
		JButton btnMolarity = new JButton("Molarity");
		btnMolarity.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				mo.setVisible(true);
			}
		});
		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		JButton btnEquationBalancing = new JButton("Equation Balancing");
		btnEquationBalancing.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				adddd.setVisible(true);
			}
		});

		JButton btnTitration = new JButton("Titration");
		btnTitration.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tit = new TitrationGui();
				tit.setVisible(true);
			}
		});

		JButton btnEmpiricalFormula = new JButton("Empirical Formula");
		btnEmpiricalFormula.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				EmpiricalFormulaGui a = new EmpiricalFormulaGui();
				a.setVisible(true);
			}
		});
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(gl_panel
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						gl_panel.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										gl_panel.createParallelGroup(
												Alignment.LEADING)
												.addGroup(
														gl_panel.createSequentialGroup()
																.addComponent(
																		lblStoichiometry)
																.addPreferredGap(
																		ComponentPlacement.UNRELATED,
																		44,
																		Short.MAX_VALUE)
																.addComponent(
																		btnMolarity)
																.addPreferredGap(
																		ComponentPlacement.UNRELATED)
																.addComponent(
																		btnPercentComposition)
																.addGap(55))
												.addGroup(
														gl_panel.createSequentialGroup()
																.addComponent(
																		btnEquationBalancing)
																.addGap(18)
																.addComponent(
																		btnTitration)
																.addPreferredGap(
																		ComponentPlacement.RELATED)
																.addComponent(
																		btnEmpiricalFormula)
																.addContainerGap(
																		67,
																		Short.MAX_VALUE)))));
		gl_panel.setVerticalGroup(gl_panel
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						gl_panel.createSequentialGroup()
								.addGap(0, 0, Short.MAX_VALUE)
								.addGroup(
										gl_panel.createParallelGroup(
												Alignment.LEADING)
												.addComponent(lblStoichiometry)
												.addGroup(
														gl_panel.createSequentialGroup()
																.addPreferredGap(
																		ComponentPlacement.RELATED)
																.addGroup(
																		gl_panel.createParallelGroup(
																				Alignment.BASELINE)
																				.addComponent(
																						btnMolarity)
																				.addComponent(
																						btnPercentComposition))))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(
										gl_panel.createParallelGroup(
												Alignment.BASELINE)
												.addComponent(
														btnEquationBalancing)
												.addComponent(btnTitration)
												.addComponent(
														btnEmpiricalFormula))));
		panel.setLayout(gl_panel);
		contentPane.add(panel);

		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1);

		JButton btnBarchart = new JButton("BarChart");
		btnBarchart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				qas.setVisible(true);
			}
		});

		JButton btnPieChart = new JButton("Pie Chart");
		btnPieChart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PetalChartFrame a = new PetalChartFrame();
				a.setVisible(true);
			}
		});
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panel_1
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								gl_panel_1
										.createParallelGroup(Alignment.LEADING)
										.addComponent(btnBarchart)
										.addComponent(btnPieChart))
						.addContainerGap(GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));
		gl_panel_1.setVerticalGroup(gl_panel_1.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panel_1
						.createSequentialGroup()
						.addComponent(btnBarchart)
						.addPreferredGap(ComponentPlacement.RELATED,
								GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(btnPieChart)));
		panel_1.setLayout(gl_panel_1);
	}
}
